package com.two.shopping.service.serviceImpl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.two.shopping.mapper.IShoppingCenterMapper;
import com.two.shopping.pojo.Commodity;
import com.two.shopping.pojo.PageBean;
import com.two.shopping.service.IShoppingCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class ShopingCenterServiceImpl implements IShoppingCenterService {
    @Autowired
    IShoppingCenterMapper iShoppingCenterMapper;

    //分页查询所有
    @Override
    public PageBean pageAll(Integer page, Integer pageSize) {
        //设置分页参数
        PageHelper.startPage(page, pageSize);
        //执行查询
        List<Commodity> empList = iShoppingCenterMapper.allIdList();
        Page<Commodity> p = (Page<Commodity>) empList;
        //封装至PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    //根据类型进行查询
    @Override
    public PageBean pageType(Integer page, Integer pageSize, Integer commodityTypeId) {
        //设置分页参数
        PageHelper.startPage(page, pageSize);
        //执行查询
        List<Commodity> empList = iShoppingCenterMapper.commodityTypeIdList(commodityTypeId);
        Page<Commodity> p = (Page<Commodity>) empList;
        //封装至PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    //模糊查询name,且可以根据价格范围进行查询
    @Override
    public PageBean pageLike(Integer page, Integer pageSize, String name, Float priceBegin, Float priceEnd) {
        //设置分页参数
        PageHelper.startPage(page, pageSize);
        //执行查询
        List<Commodity> list = iShoppingCenterMapper.pageLike(name, priceBegin, priceEnd);
        Page<Commodity> p = (Page<Commodity>) list;
        //封装至PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    //分页查询商品标号类型为id的商品信息
    @Override
    public PageBean selectCommodityId(Integer page, Integer pageSize, Integer id) {
        //设置分页参数
        PageHelper.startPage(page, pageSize);
        List<Commodity> list = iShoppingCenterMapper.commodityTypeIdList(id);
        Page<Commodity> p = (Page<Commodity>) list;
        //封装至PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    //根据ID单次查询
    @Override
    public Commodity idList(Integer id) {
        return iShoppingCenterMapper.idList(id);
    }
}
